package dao

import (
	"goWeb/bookStore/model"
	"goWeb/bookStore/utils"
)

//添加订单项
func AddOrderItem(oi *model.OrderItem) (err error) {
	sqlstr := "insert into order_items(img_path,title,author,price,count,amout,orderid) values(?,?,?,?,?,?,?)"
	_, err = utils.Db.Exec(sqlstr, oi.Img_path, oi.Title, oi.Author, oi.Price, oi.Count, oi.Amout, oi.OrderId)
	return err
}

//根据orderid获取订单详情
func GetOrderItemByOrderId(orderId string) (orderItems []*model.OrderItem, err error) {
	sqlstr := "select id,img_path,title,author,price,count,amout,orderid from order_items where orderid=?"
	rows, err := utils.Db.Query(sqlstr, orderId)
	for rows.Next() {
		oI := &model.OrderItem{}
		err = rows.Scan(&oI.Id, &oI.Img_path, &oI.Title, &oI.Author, &oI.Price, &oI.Count, &oI.Amout, &oI.OrderId)
		orderItems = append(orderItems, oI)
	}
	return
}
